<%-- 
    Document   : index
    Created on : 01/10/2009, 18:29:29
    Author     : MB
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>HttpSessionDemo-Pagina de Login</title>
    </head>
    <body>
        Sistema de Gerenciamento Hospitalar
<%import utils.Transacao;

    UserDO U = new UserDO();
    String user = request.getParameter("usuario");
    try{
        U = User.buscar(request.getParameter("usuario"));
        String Pass = U.getPassword();
        if(Pass == request.getParameter("senha")){
            if(U.getFuncionario == null){
                session.setAttribute("user_name", user);
                pageContext.forward("patient.jsp");
            }
            else{
            FuncionarioDO F = new FuncionarioDO();
            F = Funcionario.buscar(U.getFuncionario);
            string tipo = F.getFuncao();
            if (tipo == 'Medico'){
                session.setAttribute("user_name", user);
                pageContext.forward("main_med.jsp");
            }
            if (tipo == 'Recepcionita'){
                session.setAttribute("user_name", user);
                pageContext.forward("mainRecp.jsp");
            }
            if (tipo == 'Enfermeira'){
                session.setAttribute("user_name", user);
                pageContext.forward("enfermeira.jsp"); //cade?
            }
            if (tipo == 'Administrador'){
                session.setAttribute("user_name", user);
                pageContext.forward("adm.jsp"); //cadê?
            }

                                  
            }
        }
        else{
        sistem.print.out("Usuario ou Senha invalida");
        return;
        }
    }
    sistem.print.out("Usuario ou Senha invalida");
    return;
    
%>
    <form method="post" action=index2.jsp>
       Usuário <input type="text" name="usuario" />
       Senha <input type="password" name="senha" />
       <input type="submit" name="enviar" value="Enviar" />
    </form>
    </body>
</html>
